﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using WarehouseManagement.BusinessLogic.BC;
using System.Linq;
using WarehouseManagement.BusinessLogic.DTO;

namespace WarehouseManagement.Views.PO
{
    public partial class UpdateSupplierDebt : DevExpress.XtraEditors.XtraForm
    {
        private DebitBC _debitBC;

        public UpdateSupplierDebt()
        {
            InitializeComponent();
            _debitBC = new DebitBC();
        }

        private void UpdateSupplierDebt_Load(object sender, EventArgs e)
        {
            LoadSupplierAndDebts();
        }

        private void LoadSupplierAndDebts()
        {
            var list = _debitBC.GetSupplierAndDebtList().ToList();
            grdDebt.DataSource = list;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                _debitBC.UpdateAllSupplierDebts(grdDebt.DataSource as IEnumerable<SupplierAndDebtDTO>);
                XtraMessageBox.Show("Cập nhật thành công"
                    , "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(string.Format("Đã xảy ra lỗi khi cập nhật nợ nhà cung cấp. Chi tiết: {0}", ex.Message)
                    , "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}